package com.binguo.wxapi.transfer;

import com.binguo.model.model.Shop;
import com.binguo.model.wxapi.vo.ShopVO;
import com.binguo.model.wxapi.vo.ShopsVO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by haibang on 18/5/20.
 */
@Component
public class WXShopsTransfer {


    public List<ShopsVO> toShopsVOList(List<Shop> shops){

        List<ShopsVO> list = new ArrayList<>();

        Map<String, List<Shop>> cityShopMap = shops.stream().collect(Collectors.groupingBy(Shop::getCity));

        cityShopMap.forEach((k,v) -> {
          ShopsVO vo = ShopsVO.builder()
                  .city(k)
                  .shops(v.stream().map(shop ->
                    ShopVO.builder()
                        .shopId(shop.getId())
                        .shopName(shop.getName())
                        .cardImgUrl(shop.getCardimgurl()).build()
                  ).collect(Collectors.toList())).build();
          list.add(vo);
        });
        return list;
    }



}
